package com.example.demo.domain.application;

import com.example.demo.domain.application.factory.ApplicationAbstractFactory;
import com.example.demo.domain.category.Category;
import com.example.demo.domain.user.User;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.stereotype.Component;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

/**
 * 系统应用
 *
 * @author yingjianhua
 */
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString(callSuper = true)
@Entity
@DiscriminatorValue("SYSTEM")
public class SystemApplication extends Application {

    private SystemApplication(String name, String icon) {
        super(name, icon);
    }

    @Override
    public ApplicationScale getScale() {
        return ApplicationScale.SYSTEM;
    }

    @Override
    public boolean isOpen(User user) {
        return true;
    }

    @Component
    public static class SystemApplicationFactory implements ApplicationAbstractFactory {

        @Override
        public Application create(String name, Category category, String icon) {
            return new SystemApplication(name, icon);
        }
    }
}
